package com.woniu.postbar.PostConsumer;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.woniu.common.config.PostQueueConfig;
import com.woniu.postbar.pojo.PostAdmin;
import com.woniu.postbar.service.IPostAdminService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AdminConsumer {

    @Autowired
    private IPostAdminService postAdminService;


    @RabbitListener(queues = PostQueueConfig.POST_LIKE_QUEUE)
    public void getAnnounce(String name ) throws Exception{
        LambdaQueryWrapper<PostAdmin> eq = Wrappers.lambdaQuery(PostAdmin.class).eq(PostAdmin::getTitle, name);
        PostAdmin one = postAdminService.getOne(eq);
        String adminTitle= JSON.toJSON(one.getTitle()).toString();
        System.out.println("公告标题为：" + adminTitle);
        String adminNotice= JSON.toJSON(one.getNotice()).toString();
        System.out.println("公告信息为：" + adminNotice);
    }
}
